//统一封装接口方法
//每个方法负责请求一个url地址
//逻辑页面，导入这个接口方法，就能发请求
//好处：请求url路径，可以在这里统一管理

import request from "@/utils/request"

// 登录-登录注册接口 账号:13888888888 密码:246810
export const loginApi = ({
    mobile,
    code
}) => request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
        mobile, //手机号
        code //密码
    }
})

// 频道-获取所有频道
export const getAllChannelApi = () => request({
    url: '/v1_0/channels',
    method: 'GET'
})

// 频道-获取用户选择的频道
export const getUserChanneslApi = () => request({
    url: '/v1_0/user/channels',
    method: 'GET',
})

// 频道- 更新覆盖频道
export const updateChannelsApi = ({
    channels
}) => request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
        channels //用户已选择频道数组
    }
})

// 频道 - 删除用户指定的频道
export const removeTheChannelApi = ({
    channelId
}) => request({
    url: `/v1_0/user/channels/${channelId}`,
    method: 'DELETE'
})

// 搜索 - 获取联想建议（自动补全）
export const getsuggestionListApi = ({
    keywords
}) => request({
    url: '/v1_0/suggestion',
    method: 'GET',
    params: {
        q: keywords
    }
})

// 搜索 - 搜索结果列表
export const searchResultApi = ({
    page = 1,
    per_page = 10,
    q
}) => request({
    url: '/v1_0/search',
    method: 'GET',
    params: {
        page: page,
        per_page,
        q
    }
})

// 文章 - 用户获取列表
export const getAllArticleListApi = ({
    channel_id,
    timestamp
}) => request({
    url: '/v1_0/articles',
    method: 'GET',
    params: {
        channel_id,
        timestamp
    }
})

// 文章-反馈-不感兴趣
export const postdislikeArticleApi = ({
    artId
}) => request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
        target: artId
    }
})

// 文章-获取新闻详情
export const detailApi = ({
    artId
}) => request({
    url: `/v1_0/articles/${artId}`,
})

// 用户 - 关注
export const userFollowedApi = ({
    userId
}) => request({
    url: "/v1_0/user/followings",
    method: 'POST',
    data: {
        target: userId
    }
})

// 用户 - 取关
export const userUnFollowedApi = ({
    userId
}) => request({
    url: `/v1_0/user/followings/${userId}`,
    method: 'DELETE',
    data: {
        target: userId
    }
})

// 文章 - 点赞
export const likeArticleApi = ({
    artId
}) => request({
    url: "/v1_0/article/likings",
    method: 'POST',
    data: {
        target: artId
    }
})

// 文章 - 取消点赞
export const unLikeArticleApi = ({
    artId
}) => request({
    url: `/v1_0/article/likings/${artId}`,
    method: 'DELETE',
})

// 文章-反馈-反馈垃圾内容
export const reportsArticleApi = ({
    artId,
    type
}) => request({
    url: ' /v1_0/article/reports',
    method: 'POST',
    data: {
        target: artId,
        type: type,
        remark: '其他问题 的附加说明'

    }
})

// 文章-获取-评论列表
export const commentsListApi = ({
    id,
    offset = null,
    limit = 10
}) => request({
    url: '/v1_0/comments',
    method: 'GET',
    params: {
        type: 'a',
        source: id,
        offset,
        limit
    }
})